package aden.SifWar.EvtLog;

import aden.Generic.Gen2DPoint;
import aden.Generic.Param.GenParamData;
import aden.Generic.Param.GenParamException;
import aden.Generic.Param.GenParamInt;
import aden.Generic.Param.GenParamIter;
import aden.Generic.Param.GenParamNode;
import aden.SifWar.SifWarUnit;


public class SifWarEvtLogMove extends SifWarEvtLog
{
	public SifWarEvtLogMove(SifWarEvtLogMgr inMgr,
			                Gen2DPoint      inStart,
			                Gen2DPoint      inEnd)
	{
		super(inMgr);
		mStart = inStart;
		mEnd   = inEnd;
	}
		
	public boolean Process()
	{
		SifWarUnit theUnit = mMgr.GetPlayerMgr().FindUnit(mStart);
		theUnit.RealMove(mEnd.GetX(),mEnd.GetY());
		return true;
	}

	public boolean Export(GenParamNode inNode)
	{
		if (!inNode.Add(new GenParamInt("SX",mStart.GetX())) ||
		    !inNode.Add(new GenParamInt("SY",mStart.GetY())) ||
			!inNode.Add(new GenParamInt("EX",mEnd.GetX())) ||
			!inNode.Add(new GenParamInt("EY",mEnd.GetY())))
		{
			return false;
		}
		return true;
	}

	public boolean Import(GenParamIter inIter)
	{
		try
		{
		   mStart.SetX(inIter.GetNextIntContent());
		   mStart.SetY(inIter.GetNextIntContent());
		   mEnd.SetX(inIter.GetNextIntContent());
		   mEnd.SetY(inIter.GetNextIntContent());
		}
		catch (GenParamException e) 
		{
			return false;
		}
		return true;
	}
	
	public String GetDesc()
	{
		return "Move from ("+Integer.toString(mStart.GetX())+","+Integer.toString(mStart.GetX())+") to "+
	           Integer.toString(mStart.GetX())+","+Integer.toString(mStart.GetX())+")";
	}
	
	private Gen2DPoint mStart;
	private Gen2DPoint mEnd;

}
